1. Field of the Invention
Embodiments of the present invention relate generally to computer graphics and more specifically to a method for depth peeling and blending.
2. Description of the Related Art
One function of modern computer graphics systems is rendering graphics images from a set of data representing three-dimensional (3D) objects. In addition to geometry information, each 3D object may also include attributes intended to produce certain desired effects within the rendered graphics image. The displayed color of a given pixel within a rendered graphics image includes the combined effect of all attributes applied to all 3D objects, such as geometric primitives or sets of geometric primitives, intersecting the pixel within the rendered graphics image. One attribute a geometric primitive may include is transparency. An overall transparency value may be applied to the entire geometric primitive, or a texture map may be used to specify the transparency of regions on the geometric primitive. Geometric primitives that are neither fully transparent nor fully opaque are said to be “semitransparent.” Each pixel associated with a semitransparent geometric primitive may be semitransparent as well. As is well known, computing the displayed color of a semitransparent pixel involves blending the color of the pixel with the background color immediately behind the pixel, according to the degree of transparency of the semitransparent pixel.
When two or more semitransparent primitives are layered within a graphics image with respect to the view port of the graphics image, the blending order applied to the semitransparent geometric primitives must be consistently applied over all pixels on all semitransparent geometric primitives or incorrect results may be introduced. Such incorrect results may seriously diminish the overall visual quality of the graphics image.
One approach to preserving the blending order of pixels associated with semitransparent geometric primitives involves sorting the geometric primitives according to depth, relative to a specified view port, and rendering the geometric primitives in sorted order. As is well known, this approach only works in certain scenarios and produces incorrect results when semitransparent geometric primitives intersect. The intersection creates a situation where one geometric primitive is both in front of and behind the other geometric primitive, eliminating the possibility of a correct depth sorting order for the two geometric primitives.
A general, order-independent approach to rendering semitransparent geometric primitives within a rendered image is known in the art as “depth peeling,” which uses multiple passes of rendered graphics images to establish the blending order of semitransparent pixels on a per-pixel basis. In the first pass, a first color buffer and a first depth map are generated, such that only the pixel fragments that survive depth sorting are stored in the first color buffer and the first depth map stores the associated depth values. The color components (red, green and blue) and the transparency of each pixel fragment are stored in the first color buffer. In a second rendering pass, pixel fragments that are behind the corresponding first pass pixel fragments, but in front of any remaining pixel fragments, are stored in a second color buffer and corresponding depth values are stored in a second depth map. In each successive pass, a new color buffer is generated and stored, however, only two depth maps are necessary. One depth map is used for depth sorting and storing the results of the current pass, while the other depth map stores the results of the previous pass. In depth peeling, a pixel fragment survives depth sorting when the pixel fragment has a depth greater than the corresponding previously stored depth value, but is otherwise the closest pixel fragment among pixel fragments intersecting the same location within the rendered image. If the depth peeling operation performs N passes, then there are N color buffers that may be blended from back to front to establish a color buffer of pixels for display. While depth peeling generates correct transparency results, this approach requires N rendering passes and is therefore computationally expensive. The high computational expense of depth peeling diminishes overall system performance and may significantly diminish the frame rate of rendered graphics images available for display.
As the foregoing illustrates, what is needed in the art is a technique for performing efficient order-independent transparency rendering.